import { IRequestOption } from '@jl/common/composable';
import { request } from '@jl/common/utils';
/**
 * 项目列表多条件查询
 * @param requestOption - 请求参数
 * @returns
 */
// 弃用
// export const GetProListByMuCond = (
//   requestOption: IRequestOption<any, any>
// ): Promise<API.Base.ResponsePage<any>> => {
//   return request({
//     url: `/api/project/GetProListByMuCond/${requestOption.params.pageSize}/${requestOption.params.index}`,
//     method: 'GET',
//     ...requestOption,
//   });
// };
export const GetProListByMuCond = async (
  requestOption: IRequestOption<any, any>
): Promise<API.Base.ResponsePage<any>> => {
  const { params } = requestOption;
  const data = {
    current: params.index,
    pageSize: params.pageSize,
    projectName: params.blurStr,
    status: params.state === -1 ? undefined : params.state === '0' ? 0 : 1,
  };
  const res = await request({
    url: '/auth/admin/projectinfo/page',
    method: 'POST',
    data,
  });
  return {
    list: res.rows.map((el: any) => ({
      ...el,
      projectId: el.projectCode,
      label: el.projectName,
      value: el.projectCode,
    })),
    count: res.total,
  };
};

export const createProject = (
  requestOption: IRequestOption<any, any>
): Promise<API.Base.ResponsePage<any>> => {
  return request({
    url: `/api/project/createProject`,
    method: 'POST',
    ...requestOption,
  });
};

export const editProject = (
  requestOption: IRequestOption<any, any>
): Promise<API.Base.ResponsePage<any>> => {
  return request({
    url: `/api/project/editRecord`,
    method: 'PUT',
    headers: { 'Content-Type': 'multipart/form-data' },
    ...requestOption,
  });
};

export const stateSwitch = (
  requestOption: IRequestOption<any, any>
): Promise<API.Base.ResponsePage<any>> => {
  return request({
    url: `/api/project/stateSwitch`,
    method: 'PUT',
    headers: { 'Content-Type': 'multipart/form-data' },
    ...requestOption,
  });
};

export const delRecord = (
  requestOption: IRequestOption<any, any>
): Promise<API.Base.ResponsePage<any>> => {
  return request({
    url: `/api/project/delRecord`,
    method: 'DELETE',
    ...requestOption,
  });
};

// 根据appid获取集团列表
export const getGroupByAppId = async (data: { appId: string }): Promise<any> => {
  return await request({
    url: '/auth/admin/appidcompanyrelation/appIdByCompany',
    method: 'POST',
    data,
  });
};

// 获取用户拥有权限的第一个集团【公司】信息
export const getLicensedFirstCompany = async (): Promise<any> => {
  return await request({
    url: '/auth/api/cimup/cimupCompany/getLicensedFirstCompany',
    method: 'GET',
  });
};

// 组织架构-列表
export const getOrganizationTree = async (data: any): Promise<any> => {
  const result = await request({
    url: '/auth/admin/orgInfo/treeNodes',
    method: 'POST',
    data,
  });

  return {
    rows: result,
    total: result.length,
  };
};

/**
 * 查询项目信息
 */
export const getProjects = async (data: any): Promise<any> => {
  return await request({
    url: '/auth/admin/projectinfo/page',
    method: 'POST',
    data,
  });
};

/**
 * 新增项目信息
 */
export const addProject = async (data: any): Promise<any> => {
  return request({
    url: '/auth/admin/projectinfo/add',
    method: 'POST',
    data,
  });
};

/**
 * 修改项目信息
 */
export const updateProject = async (data: any): Promise<any> => {
  return await request({
    url: '/auth/admin/projectinfo/update',
    method: 'POST',
    data,
  });
};

/**
 * 删除项目信息
 */
export const deleteProject = async (data: { id: number }): Promise<any> => {
  return await request({
    url: '/auth/admin/projectinfo/delete',
    method: 'POST',
    data,
  });
};

/**
 * 项目启用
 */
export const enableProject = async (data: { id: number }): Promise<any> => {
  return await request({
    url: '/auth/admin/projectinfo/enable',
    method: 'POST',
    data,
  });
};

/**
 * 项目停用
 */
export const blockUpProject = async (data: { id: number }): Promise<any> => {
  return await request({
    url: '/auth/admin/projectinfo/blockUp',
    method: 'POST',
    data,
  });
};
